﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;

namespace RiskMan.DataClass.Models.Plaza_II.FortsFutInfoRepl
{
    /// <summary>
    /// Таблица 68. Поля таблицы futures_params - Параметры фьючерсов
    /// </summary>
    public class FuturesParams: INotifyPropertyChanged
    {
        #region private

        private long _replId;
        private long _replRev;
        private long _replAct;
        private string _isin;
        private int _isinId;
        private string _codeVcb;
        private Decimal _limit;
        private Decimal _settlPrice;
        private int _spreadAspect;
        private int _subrick;
        private Decimal _stepPrice;
        private Decimal _baseGo;
        private DateTime _expDate;
        private int _spotSigns;
        private Decimal _setllPriceReal;
        private Decimal _minStep;

        #endregion

        #region public

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplId
        {
            get { return _replId; }
            set
            {
                if (_replId != value)
                {
                    _replId = value;
                    RaisePropertyChanged("ReplId");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplRev
        {
            get { return _replRev; }
            set
            {
                if (_replRev != value)
                {
                    _replRev = value;
                    RaisePropertyChanged("ReplRev");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplAct
        {
            get { return _replAct; }
            set
            {
                if (_replAct != value)
                {
                    _replAct = value;
                    RaisePropertyChanged("ReplAct");
                }
            }
        }
        
        /// <summary>
        /// Идентификатор инструмента
        /// </summary>
        public string Isin
        {
            get { return _isin; }
            set
            {
                if (_isin != value)
                {
                    _isin = value;
                    RaisePropertyChanged("Isin");
                }
            }
        }
           
        /// <summary>
        /// Уникальный числовой идентификатор инструмента
        /// </summary>
        public int IsinId
        {
            get { return _isinId; }
            set
            {
                if (_isinId != value)
                {
                    _isinId = value;
                    RaisePropertyChanged("IsinId");
                }
            }
        }
        
        /// <summary>
        /// Код базового контракта
        /// </summary>
        public string CodeVcb
        {
            get { return _codeVcb; }
            set
            {
                if (_codeVcb != value)
                {
                    _codeVcb = value;
                    RaisePropertyChanged("CodeVcb");
                }
            }
        }
        
        /// <summary>
        /// Лимит колебания цены контракта
        /// </summary>
        public Decimal Limit
        {
            get { return _limit; }
            set
            {
                if (_limit != value)
                {
                    _limit = value;
                    RaisePropertyChanged("Limit");
                }
            }
        }
        
        /// <summary>
        /// Расчетная цена
        /// </summary>
        public Decimal SettlPrice
        {
            get { return _settlPrice; }
            set
            {
                if (_settlPrice != value)
                {
                    _settlPrice = value;
                    RaisePropertyChanged("SettlPrice");
                }
            }
        }
        
        /// <summary>
        /// Признак вхождения в спрэд
        /// </summary>
        public int SpreadAspect
        {
            get { return _spreadAspect; }
            set
            {
                if (_spreadAspect != value)
                {
                    _spreadAspect = value;
                    RaisePropertyChanged("SpreadAspect");
                }
            }
        }
        
        /// <summary>
        /// Признак учета рисков по подточкам риска
        /// </summary>
        public int Subrick
        {
            get { return _subrick; }
            set
            {
                if (_subrick != value)
                {
                    _subrick = value;
                    RaisePropertyChanged("Subrick");
                }
            }
        }
        
        /// <summary>
        /// Цена минимального шага
        /// </summary>
        public Decimal StepPrice
        {
            get { return _stepPrice; }
            set
            {
                if (_stepPrice != value)
                {
                    _stepPrice = value;
                    RaisePropertyChanged("StepPrice");
                }
            }
        }
        
        /// <summary>
        /// Базовое ГО
        /// </summary>
        public Decimal BaseGo
        {
            get { return _baseGo; }
            set
            {
                if (_baseGo != value)
                {
                    _baseGo = value;
                    RaisePropertyChanged("BaseGo");
                }
            }
        }
        
        /// <summary>
        /// Дата экспирации
        /// </summary>
        public DateTime ExpDate
        {
            get { return _expDate; }
            set
            {
                if (_expDate != value)
                {
                    _expDate = value;
                    RaisePropertyChanged("ExpDate");
                }
            }
        }

        
        /// <summary>
        /// Признак спот-фьючерса
        /// </summary>
        public int SpotSigns
        {
            get { return _spotSigns; }
            set
            {
                if (_spotSigns != value)
                {
                    _spotSigns = value;
                    RaisePropertyChanged("SpotSigns");
                }
            }
        }
        
        /// <summary>
        /// Реальная расчетная цена фьючерса
        /// </summary>
        public Decimal SetllPriceReal
        {
            get { return _setllPriceReal; }
            set
            {
                if (_setllPriceReal != value)
                {
                    _setllPriceReal = value;
                    RaisePropertyChanged("SetllPriceReal");
                }
            }
        }
        
        /// <summary>
        /// Минимальный шаг изменения цены
        /// </summary>
        public Decimal MinStep
        {
            get { return _minStep; }
            set
            {
                if (_minStep != value)
                {
                    _minStep = value;
                    RaisePropertyChanged("MinStep");
                }
            }
        }

        #endregion


        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region processing
        public static FuturesParams ParseFuturesParams(Dictionary<String, String> relation)
        {
            FuturesParams tmp = new FuturesParams();
            tmp.Parse(relation);
            return tmp;
        }

        public void Parse(Dictionary<String, String> relation)
        {
            foreach (String field in relation.Keys)
            {
                String value = relation[field];

                switch (field)
                {

                    case "replID": long.TryParse(value, out _replId); break;
                    case "replRev": long.TryParse(value, out _replRev); break;
                    case "replAct": long.TryParse(value, out _replAct); break;
                    case "isin": _isin = value; break;
                    case "isin_id": int.TryParse(value, out _isinId); break;
                    case "code_vcb": _codeVcb = value; break;
                    case "limit": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _limit); break;
                    case "settl_price": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _settlPrice); break;
                    case "spread_aspect": int.TryParse(value, out _spreadAspect); break;
                    case "subrick": int.TryParse(value, out _subrick); break;
                    case "step_price": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _stepPrice); break;
                    case "base_go": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _baseGo); break;
                    case "exp_date": DateTime.TryParse(value, out _expDate); break;
                    case "spot_signs": int.TryParse(value, out _spotSigns); break;
                    case "setll_price_real": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _setllPriceReal); break;
                    case "min_step": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _minStep); break; 


                };
            }
        }
       
        public static void AddValueToObsColFuturesParams(FuturesParams inst)
        {
            MainWindow.StaticLevel._dataProvider.FuturesParamsList.Add(inst);
        }
        #endregion
    }
}
